home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / Apple Game Sprockets / Examples / DroneZone / DZMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-16  |  3.4 KB  |  176 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    File:        DZMain.c
  3.  *    Author:        Dan Venolia
  4.  *
  5.  *    Contents:    Main entry point, main loop, initialize and exit code
  6.  *
  7.  *    Copyright © 1996 Apple Computer, Inc.
  8.  */
  9.  
  10. #include <Dialogs.h>
  11. #include <Fonts.h>
  12. #include <Memory.h>
  13. #include <QuickDraw.h>
  14. #include <Types.h>
  15. #include <Windows.h>
  16.  
  17. #include <QD3D.h>
  18.  
  19. #include "DZDisplay.h"
  20. #include "DZDrone.h"
  21. #include "DZEvents.h"
  22. #include "DZGame.h"
  23. #include "DZInput.h"
  24. #include "DZMain.h"
  25. #include "DZMenu.h"
  26. #include "DZSound.h"
  27. #include "DZSpace.h"
  28.  
  29.  
  30. #ifdef APP_LOADS_SOUND_COMPONENT
  31.     #include "S3Private.h"
  32. #endif
  33.  
  34. void main(
  35.     void);
  36.  
  37. static void Init(
  38.     void);
  39.  
  40. static void Exit(
  41.     void);
  42.  
  43.  
  44. static Boolean gAlive = false;
  45.  
  46.  
  47.  
  48. /* =============================================================================
  49.  *        main
  50.  *
  51.  *    Initializes, processes events, does the idle-time stuff, and exits.
  52.  * ========================================================================== */
  53. void main(
  54.     void)
  55. {
  56.     Init();
  57.     
  58.     while (gAlive)
  59.     {
  60.         Events_Process();
  61.         
  62.         if (gAlive && Display_IsActive() && Game_GetState() == kGameState_Playing)
  63.         {
  64.             Game_Process();
  65.             Display_DrawContents();
  66.         }
  67.     }
  68.     
  69.     Exit();
  70. }
  71.  
  72.  
  73. /* =============================================================================
  74.  *        Main_LastRoundup (external)
  75.  *
  76.  *    Requests the main event loop to gracefully exit.
  77.  * ========================================================================== */
  78. void Main_LastRoundup(
  79.     void)
  80. {
  81.     gAlive = false;
  82. }
  83.  
  84.  
  85. /* =============================================================================
  86.  *        Init (internal)
  87.  *
  88.  *    Initialization of toolbox and our stuff.
  89.  * ========================================================================== */
  90. void Init(
  91.     void)
  92. {
  93.     // Initialize the toolbox
  94.      MaxApplZone();
  95.     MoreMasters();
  96.     
  97.     InitGraf(&qd.thePort);
  98.     InitFonts();
  99.     InitWindows();
  100.     InitDialogs(NULL);
  101.     InitCursor();
  102.     InitMenus();
  103.     TEInit();
  104.     
  105.     qd.randSeed = TickCount();
  106.     
  107.     // Initialize QD3D
  108.     Q3Initialize();
  109.     
  110.     // Should we load S3Localization?
  111.     #ifdef APP_LOADS_SOUND_COMPONENT
  112.     {
  113.         ComponentDescription    filterDesc;
  114.         Handle                    filterNameHdl, infoHdl;
  115.         
  116.         // Register (or find) our components
  117. #ifdef REAL_3D_INSTALL
  118.         filterDesc.componentType            = kSoundEffectsType;
  119. #else
  120.         filterDesc.componentType            = 'sdec';
  121. #endif
  122.         filterDesc.componentSubType            = kSSpLocalizationSubType;
  123.         filterDesc.componentManufacturer    = kAppleManufacturer;
  124.         filterDesc.componentFlags            = 0L;
  125.         filterDesc.componentFlagsMask        = 0L;
  126.         
  127.         filterNameHdl = NewHandle (sizeof (Str255));
  128.         BlockMove ((Ptr)"\pS3Localization", (Ptr)(*filterNameHdl), sizeof (Str255));
  129.  
  130.         infoHdl = NewHandle (sizeof (Str255));
  131.         BlockMove ((Ptr)"\pThis component provides 3D Audio.", (Ptr)(*infoHdl), sizeof (Str255));
  132.         
  133.         // Register the Filter component
  134.         RegisterComponent (&filterDesc, NewComponentRoutineProc(SoundComponentProc), kRegisterGlobally,
  135.             filterNameHdl, infoHdl, nil);
  136.     }
  137.     #endif
  138.     
  139.     // Initialize our modules
  140.     Menu_Init();
  141.     Sound_Init();
  142.     Events_Init();
  143.     Display_Init();
  144.     Drone_Init();
  145.     Space_Init();
  146.     Input_Init();
  147.     Game_Init();
  148.     
  149.     // We're off...
  150.     gAlive = true;
  151. }
  152.  
  153.  
  154. /* =============================================================================
  155.  *        Exit (internal)
  156.  *
  157.  *    Cleans up before exit.
  158.  * ========================================================================== */
  159. void Exit(
  160.     void)
  161. {
  162.     // Exit our modules
  163.     Game_Exit();
  164.     Input_Exit();
  165.     Space_Exit();
  166.     Drone_Exit();
  167.     Display_Exit();
  168.     Events_Exit();
  169.     Sound_Exit();
  170.     Menu_Exit();
  171.     
  172.     // Exit QD3D
  173.     Q3Exit();
  174. }
  175.  
  176.